﻿using System;
using COM.DTO;
using NHibernate;
using COM.Logging;
using NHibernate.Criterion;

namespace DAL.DAO
{
    class ContactDAO
    {
        public static void Add(Contact contact)
        {
            {
                using (ISession session = NHibernateHelper.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.SaveOrUpdate(contact);
                    transaction.Commit();
                }
            }
        }
        public static void Update(Contact contact)
        {
            {
                using (ISession session = NHibernateHelper.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Update(contact);
                    transaction.Commit();
                }
            }
        }

        public static void Remove(Contact contact)
        {
            {
                using (ISession session = NHibernateHelper.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Delete(contact);
                    transaction.Commit();
                }
            }
        }

        public static Contact GetContactById(String ContactId)
        {
            using (ISession session = NHibernateHelper.OpenSession())
                return session.Get<Contact>(ContactId);
        }
        /*
        public static Contact GetContactByContactId(string ContactId)
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                var contact = session
                    .CreateCriteria(typeof(Contact))
                    .Add(Restrictions.Eq("ContactId", ContactId))
                    .UniqueResult<Contact>();
                return contact;
            }

        } */
    }
}
